<template>
<div>
  <table>
    <tr>
      <td>商品名</td>
      <td>价格</td>
      <td>操作</td>
    </tr>
    <tr v-for="i in list">
      <td>{{i.name}}</td>
      <td>{{i.price}}</td>
      <td>
        <button @click="add(i.id)">购买</button>
      </td>
    </tr>
  </table>
</div>
</template>

<script>
export default {
  name: "ccgoods",
  data(){
    return{
      list:[],
      userid:localStorage.getItem('userid')
    }
  },
  methods:{
    show_goods(){
      this.$axios('goods/goods')
      .then(i=>{
        this.list = i.data.list
      })
    },
    add(id){
      if (this.userid){
        this.$axios.post('goods/car',{userid:this.userid,goodsid:id,count:1})
        .then(i=>{


        })
      }

    }
  },
  mounted() {
    this.show_goods()
  }
}
</script>

<style scoped>

</style>
